package com.jit.app.repository;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class DownloadInfoRepository {

    SQLiteDatabase database;

    public DownloadInfoRepository(Context context){
        database = context.openOrCreateDatabase("download",Context.MODE_PRIVATE, null);
        database.execSQL("create table if not exists downloads(_id integer primary key autoincrement, pack varchar(100), apkPath varchar(100))");
    }

    public long addDownloadInfo(String pack, String apkPath){
        ContentValues contentValues = new ContentValues();
        contentValues.put("pack",pack);
        contentValues.put("apkPath", apkPath);
        return database.insert("downloads", null, contentValues);
    }

    public String getDownloadInfoByPack(String pack){
        Cursor cursor = database.query("downloads", new String[]{"apkPath"},"pack=?",new String[]{pack},null,null,null);
        String apkPath = null;
        if (cursor.moveToNext()){
            apkPath = cursor.getString(cursor.getColumnIndex("apkPath"));
        }
        return apkPath;
    }
}
